package cn.py.boot_lua.processTa;

import cn.py.boot_lua.handler.generic.QueueType;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;

/**
 * 定义信号量容器
 */
@Component
public class TaskSemaphoreManager {

    private final Map<QueueType, Semaphore> semaphoreMap = new ConcurrentHashMap<>();

    // 每个类型最多2个并发
    public TaskSemaphoreManager() {
        for (QueueType type : QueueType.values()) {
            semaphoreMap.put(type, new Semaphore(2));
        }
    }

    public Semaphore getSemaphore(QueueType queueType) {
        return semaphoreMap.get(queueType);
    }
}
